import time
from datetime import datetime
from datetime import date

t = time.time()  # 时间戳：1970年
print(t)
t = time.localtime()  # 结构化的时间
print(t)
"""day of week, range [0, 6], Monday is 0"""
print(t.tm_wday)
print(t.tm_mday)
print(t.tm_yday)
print(t.tm_year, type(t.tm_year))  # 获取
s = time.strftime('%Y-%m-%d %H:%M:%S', t)
print(s)
from my_package import my_tools

print(my_tools.get_time())
# 将格式字符串转换为时间戳
a = "Sat Mar 28 22:24:24 2016"
print(time.mktime(time.strptime(a, "%a %b %d %H:%M:%S %Y")))
bbb = "2023-01-20 17:19:23"
bbbTime = time.strptime(bbb, "%Y-%m-%d %H:%M:%S")
print(bbbTime.tm_year, bbbTime.tm_mon)

print("-" * 50)

# 指定日期
specified_date = "2023-01-20 17:19:23"

# 将指定日期转换为datetime对象
specified_datetime = time.strptime(specified_date, "%Y-%m-%d %H:%M:%S")

# datetime对象转换成时间字符串
datetime_str = datetime(2023, 1, 3, 17, 19, 23, 0)
datetime_str2 = datetime.now()
print(datetime_str>datetime_str2)


# 打印结果
print(specified_datetime)
print(specified_datetime.date())
print(specified_datetime.time())

print("-" * 50)

my_date = date(2023, 1, 20)
my_date2 = datetime(2023, 1, 3, 17, 19, 23)
print(my_date2)
# 获取年份
print(my_date.year)

# 获取月份
print(my_date.month)

# 获取日期
print(my_date.day)

# 格式化日期为字符串
print(my_date.strftime("%Y-%m-%d"))
